package com.crawler.gmail.model;

import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;

/**
 * <描述>
 * <详细介绍>
 *
 * @author 王明明
 * @since wiki
 */
public class EmailFetchSettingModel {

    private String settingId;
    private String email;
    private String password;
    private Integer protocol;
    private String hostname;
    private Integer port;
    private Boolean ssl;
    private String fetchDate;
    private Integer status;
    private Integer valid;
    private String accountSettingId;


    public EmailFetchSettingModel() {

    }
    public EmailFetchSettingParam convertParam() {
        EmailFetchSettingParam param = new EmailFetchSettingParam();
        param.setSettingId(this.settingId);
        param.setEmail(this.email);
        param.setPassword(this.password);
        param.setProtocol(this.protocol);
        param.setHostname(this.hostname);
        param.setPort(this.port);
        param.setSsl(this.ssl ?1:0);
        param.setFetchDate(this.fetchDate);
        param.setStatus(this.status);
        param.setValid(this.valid);
        return param;
    }





    /*public static EmailFetchSettingDO convertDO(String companyId,String accountId,EmailFetchSettingModel model) {
        EmailFetchSettingDO settingDO = new EmailFetchSettingDO();
        settingDO.setSettingId(model.getSettingId());
        settingDO.setCompanyId(companyId);
        settingDO.setAccountId(accountId);
        settingDO.setEmail(model.getEmail());
        settingDO.setPassword(model.getPassword());
        if (model.getProtocol() != null) {
            settingDO.setProtocol(EEmailProtocolEnum.findByValue(model.getProtocol()));
        }
        settingDO.setHostname(model.getHostname());
        settingDO.setPort(model.getPort());
        settingDO.setSsl(model.getSsl());
        Long millis = DateUtil.getMillisFromStringByFormat(model.getFetchDate(), "yyyy-MM-dd") / 1000L;
        settingDO.setFetchDate(millis.intValue());
        settingDO.setStatus(model.getStatus());
        settingDO.setValid(model.getValid());
        settingDO.setAccountSettingId(model.getAccountSettingId());

        if(CollectionUtils.isEmpty(model.getAuthAccounts())){
            settingDO.setAuthAccountIds(new ArrayList<String>());
        }else{
            settingDO.setAuthAccountIds(Lists.transform(model.getAuthAccounts(), new Function<AuthAccount, String>() {
                @Override
                public String apply(AuthAccount authAccount) {
                    return authAccount.getId();
                }}
            ));
        }
        return settingDO;
    }*/

    /*public static EmailFetchSettingModel convertToModel(EmailFetchSettingDO settingDO,List<AuthAccount> authAccounts) {
        EmailFetchSettingModel model = new EmailFetchSettingModel();
        model.setValid(settingDO.getValid());
        model.setEmail(settingDO.getEmail());
        model.setHostname(settingDO.getHostname());
        //密码不显示
        model.setPassword("");
        model.setPort(settingDO.getPort());
        model.setSettingId(settingDO.getSettingId());
        model.setProtocol(settingDO.getProtocol().getValue());
        model.setSsl(settingDO.getSsl());
        model.setStatus(settingDO.getStatus());
        String dateString = "-";
        if (settingDO.getFetchDate() != null) {
            DateUtil.convertTimestampSecondsToString(settingDO.getFetchDate(), "yyyy-MM-dd");
        }
        model.setFetchDate(dateString);
        model.setAuthAccounts(authAccounts);
        model.setAccountSettingId(settingDO.getAccountSettingId());
        return model;
    }*/

    public String getSettingId() {
        return settingId;
    }

    public void setSettingId(String settingId) {
        this.settingId = settingId;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getProtocol() {
        return protocol;
    }

    public void setProtocol(Integer protocol) {
        this.protocol = protocol;
    }

    public String getHostname() {
        return hostname;
    }

    public void setHostname(String hostname) {
        this.hostname = hostname;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public Boolean getSsl() {
        return ssl;
    }

    public void setSsl(Boolean ssl) {
        this.ssl = ssl;
    }

    public String getFetchDate() {
        return fetchDate;
    }

    public void setFetchDate(String fetchDate) {
        this.fetchDate = fetchDate;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getValid() {
        return valid;
    }

    public void setValid(Integer valid) {
        this.valid = valid;
    }


    public String getAccountSettingId() {
        return accountSettingId;
    }

    public void setAccountSettingId(String accountSettingId) {
        this.accountSettingId = accountSettingId;
    }

}
